package org.nf.box.web.controller;

import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.nf.box.common.result.ResultVO;
import org.nf.box.domain.User;
import org.nf.box.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lzp
 * @Date 2024-11-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController extends BaseController {

    protected final UserService userService;

    @GetMapping("/get")
    public ResultVO<List<User>> listUser(@RequestParam("page") int page,
                                         @RequestParam("limit") int limit) {
        PageInfo<User> pageInfo = userService.listUser(page, limit);
        ResultVO<List<User>> resultVO = new ResultVO<>();
        resultVO.setCode(200);
        resultVO.setData(pageInfo.getList());
        return resultVO;
    }

    @PostMapping("/add")
    public ResultVO<User> addUser(@RequestBody User user){
        userService.addUser(user);
        return new ResultVO<>(200,"添加成功",user);
    }

    @GetMapping("/id")
    public  ResultVO getUserId(@RequestAttribute("user") Integer id){
        System.out.println("id:"+id);
        return success(id);
    }

}
